﻿using System.Runtime.CompilerServices;
using Dogshow.Model.Extensions;
using Dogshow.Model.Validation;
using FluentValidation.Attributes;

namespace Dogshow.Model
{
    [Validator(typeof(MestoValidator))]
    public class Mesto : Entity
    {
        public int Id { get; set; }
        private string m_PostanskiBroj;
        public string PostanskiBroj
        {
            get { return m_PostanskiBroj; }
            set
            {
                if (PostanskiBroj != value)
                {
                    m_PostanskiBroj = value.TrimAndNull();
                    OnPropertyChanged("PostanskiBroj");
                }
            }
        }

        private string m_Naziv;
        public string Naziv
        {
            get { return m_Naziv; }
            set
            {
                if (Naziv != value)
                {
                    m_Naziv = value.TrimNullAndToUpper();
                    OnPropertyChanged("Naziv");
                }
            }
        }

        public bool Equals(Mesto other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.Id == Id;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Mesto)) return false;
            return Equals((Mesto) obj);
        }

        public override int GetHashCode()
        {
            return Id;
        }
    }
}